<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require '../com.swiss.mooh.dao.impl/ContactDaoImpl.php';
require '../com.swiss.mooh.service/ContactServiceImpl.php';
require '../com.swiss.mooh.model/Contact.php';

$dispatcher = new ContactDaoImpl();
$contactService = new ContactServiceImpl($dispatcher);

if ($_POST['type'] == 0) {
    $contactTO = new Contact();
    $contactTO->setContactID(uniqid());
    $contactTO->setContactDescription($_POST['contactDesc']);
    $contactTO->setContactCreateDateTime(date('Y-m-d h:i:s a', time()));
    $result = $contactService->createContact($contactTO);
    echo $result;
}
if ($_POST['type'] == 1) {
    $contactTO = new Contact();
    $contactTO->setContactID($_POST['contactID']);
    $contactTO->setContactDescription($_POST['contactDesc']);

    $result = $contactService->updateContact($contactTO);
    echo $result;
}
if ($_POST['type'] == 2) {
    $resultList = $contactService->getContactContent();
    $resultVO = $resultList->GetObj(0);
    if ($resultVO != null) {
        $resultArray = array('ContactID' => $resultVO->getContactID(), 'ContactDesc' => $resultVO->getContactDescription(), 'ContactCreatedDate' => $resultVO->getContactCreateDateTime());
        echo json_encode($resultArray);
    }
}